//
//  KBLikeTableViewCell.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//
// 正常格式Cell
#import "KBLikeTableViewCell.h"
#import "KBLikeModel.h"
@interface KBLikeTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property(nonatomic,strong)NSMutableArray *arr;
@end

@implementation KBLikeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.arr = [NSMutableArray array];
        [self createSubViews];
    }
    return self;
}
-(void)setCellModel:(KBLikeModel *)cellModel{
    self.arr = cellModel.list;
    [self.myCollectV reloadData];
    
}
- (void)createSubViews{
    UICollectionViewFlowLayout *myFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 每个cell大小
    myFlowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-60)/3+6.5, (SCREEN_WIDTH - 60)/3+50);
    // 设置最小行间距
//    myFlowLayout.minimumLineSpacing = 18;
    // 每个cell间距
    myFlowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    // collectionView滚动方向
    myFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.myCollectV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, (SCREEN_WIDTH - 60)/3+80) collectionViewLayout:myFlowLayout];
    self.myCollectV.backgroundColor = [UIColor whiteColor];
    self.myCollectV.delegate = self;
    self.myCollectV.dataSource = self;
    [self.contentView addSubview:self.myCollectV];
    
    [self.myCollectV registerClass:[KBLikeCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.myCollectV reloadData];
    
}
// 每个section有几个item
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    KBLikeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
//    cell.backgroundColor = [UIColor grayColor];
    cell.cellDic = [_arr objectAtIndex:indexPath.row];
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.likeDelegate LikeViewdelegate:indexPath arr:_arr];
}













- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
